import React from 'react'
import {inject, observer} from 'mobx-react'
import {message} from 'antd'

const HOCStoreGoodsShows = WarpComponent=>{
    @inject('setStoreInfo')
    @observer
    class ElementComponent extends React.Component{
        componentDidMount(){
            let {getGoodsShowSet} = this.props.setStoreInfo
            getGoodsShowSet().then(data=>{
                if (data.data.code === 200) {
                    let allData = data.data.data[0]
                    this.setForm(allData)
                }else{
                    message.error('查询数据失败')
                }
            })
        }
        setForm=(obj)=>{
            let {formOne} = this.refs.form.refs
            formOne.setFieldsValue(obj)
        }
        submit=()=>{
            let {formOne} = this.refs.form.refs
            let {updateGoodsShowSet} = this.props.setStoreInfo
            let key = [
                'numberStatu',
                'weightStatu',
                'inventoryStatu',
                'priceStatu'
            ]
            let form = formOne.getFieldsValue(key)
            form.comdDisplayId = 1
            updateGoodsShowSet(form).then(data=>{
                if (data.data.code === 200) {
                    message.success('更新数据成功')
                }else{
                    message.error('更新数据失败')
                }
            })
        }
        render() {
            let methods = {
                submit:this.submit
            }
            return (
                <div>
                    <WarpComponent ref='form' {...methods}></WarpComponent>
                </div>
            );
        }
    }
    return ElementComponent
}

export default HOCStoreGoodsShows